﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MyMainSite.Models;

namespace MyMainSite.Repositories
{
    public static class BlogRepository
    {
        #region Public Static Methods

        public static List<Blog> GetByBlogUserId(int blogUserId)
        {
            RichardsSiteEntities context = new RichardsSiteEntities();

            var blogs = from b in context.Blogs
                        where b.BlogUserId == blogUserId
                        select b;

            return blogs.ToList();
        }

		public static int AddBlogForProject(int projectId, int userId, IProjectRepository projectRepo)
		{
			var project = projectRepo.GetProjectById(projectId);

			string friendlyUrl = project.FriendlyUrl;

			RichardsSiteEntities context = new RichardsSiteEntities();

			Blog b = new Blog();

			b.Name = project.Name;
			b.FriendlyUrl = project.FriendlyUrl;
			b.ProjectId = project.ProjectId;
			b.BlogUserId = userId;

			context.Blogs.AddObject(b);
			context.SaveChanges();

			return b.BlogId;
		}

        #endregion
    }
}